#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#define eps 1e-6
#define INF 0x3f3f3f3f
#define inf 1e18
#define ll long long
#define db double
#define pb push_back
#define mk make_pair
inline int read(){
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
using namespace std;
#define M 100005
#define N 300005
int n,B,K,Q,ori[M],a[M],d[N],winner[N];
ll ans[M];
struct query{
    int c,id;
    friend bool operator<(query a,query b){
        return a.c>b.c;
    }
}que[M];
int Flag;
int dfs(int layer,int u){
    if(layer==0) return u-B;
    int x=dfs(layer-1,u<<1);
    int y=dfs(layer-1,u<<1|1);
    if(Flag) printf("%d %d %d %d %d %d %d\n",layer,u,d[u],x,y,a[x],a[y]);
    if(d[u]==0){
        return winner[u]=(a[x]>=layer?x:y);
    }else{
        return winner[u]=(a[y]>=layer?y:x);
    }
}
ll dfs2(int layer,int u){
    if(Flag) printf("%d\n",u);
    if(layer==0){
        if(~a[u-B]) return 0;
        else return u-B;
    }
    ll res=0;
    res+=dfs2(layer-1,u<<1);
    if(winner[u]==(u<<1|1)||d[u]) res+=dfs2(layer-1,u<<1|1);
    return res;
}
void solve(){
    int X[4];
    for(int i=0;i<4;i++) X[i]=read();
    for(int i=1;i<=n;i++) a[i]=ori[i]^X[i%4];
    for(int i=1;i<=Q;i++) ans[i]=0;
    int lst=n+1;
    for(int i=1;i<=Q;i++){
        if(que[i].c==que[i-1].c){
            ans[que[i].id]=ans[que[i-1].id];
            continue;
        }
        for(int j=que[i].c+1;j<=n;j++) a[j]=-1;
        int K0=0;
        for(K0=0;(1<<K0)<que[i].c;K0++);
        if(que[i].c==3) Flag=1;
        else Flag=0;
        int rt=1<<(K-K0);
        int u=dfs(K0,rt);
        ll val=dfs2(K0,rt);
        printf("%d %d %lld\n",que[i].c,u,val);
        if(u<=que[i].c) ans[que[i].id]=val+u;
        else ans[que[i].id]=val;
    }
    ll res=0;
    for(int i=1;i<=Q;i++) res^=(i*ans[i]);
    printf("%lld\n",res);
}
int main(){
    freopen("arena1.in","r",stdin);
    //freopen("arena.out","w",stdout);
    n=read(),Q=read();
    for(int i=1;i<=n;i++) ori[i]=read();
    for(int i=1;i<=Q;i++) que[i].c=read(),que[i].id=i;
    sort(que+1,que+Q+1);
    memset(a,-1,sizeof(a));
    for(K=0;(1<<K)<n;K++);
    B=(1<<K)-1;
    for(int G=K;G;G--){
        for(int R=1;R<=1<<(G-1);R++){
            int begin=(1<<(G-1))-1;
            char ch=getchar();
            while(ch!='0'&&ch!='1') ch=getchar();
            d[begin+R]=ch-'0';
        }
    }
    int T=read();T=1;
    while(T--) solve();
    return 0;
}